<!--
*  2021-03-15
*  成品跟踪  预计汇总
-->
<template>
  <div id="app" class="view-except">
    <!-- 头部导航 -->
    <van-nav-bar
      ref="header"
      :title="title"
      left-arrow
      @click-left="onClickLeft"
      left-text="返回"
    >
    </van-nav-bar>

    <!-- 搜索 -->
    <van-search
      v-if="!isColor"
      v-model="keyLike"
      placeholder="输入搜索颜色关键词"
      @search="onClickSearch"
    ></van-search>
    <!-- 滚动 -->
    <better-scroll
      class="public-scroll"
      :data="tableData"
      :totalPage="totalPage"
    >
      <van-cell-group v-show="tableData.length !== 0">
        <van-cell
          v-for="(data, index) in tableData"
          :key="index"
          :title="data.color"
          is-link
          :value="data.exceptNum"
          @click="onClickExceptDetail(data)"
        >
        </van-cell>
      </van-cell-group>
      <van-empty
        class="custom-image"
        image="https://img01.yzcdn.cn/vant/custom-empty-image.png"
        v-show="tableData.length === 0"
        description="暂无数据"
      />
    </better-scroll>
  </div>
</template>

<script>
import { openWin } from "@/utils/index";
import { getProductExceptList } from "@/api/product";

export default {
  name: "productViewExcept",
  data() {
    return {
      title: "",
      totalPage: 1,
      tableData: [],
      designNo: "",
      color: "",
      isColor: false,
      keyLike: "",
    };
  },
  mounted() {
    const that = this;
    if (process.env.NODE_ENV === "production") {
      this.$nextTick(() => {
        that.initFn(that);
      });
    } else {
      window.apiready = function () {
        that.initFn(that);
      };
    }
  },
  methods: {
    //初始化
    initFn(that) {
      that.designNo = window.api.pageParam.designNo;
      that.color = window.api.pageParam.color;
      that.isColor = window.api.pageParam.isColor;
      that.title = window.api.pageParam.title;
      that.onGetTableData();
    },
    // 返回
    onClickLeft() {
      if (!this.isColor) {
        openWin("product-view", {
          scrollY: window.api.pageParam.scrollY,
          keyLike: window.api.pageParam.keyLike
        });
      } else {
        openWin("view-color", {
          designNo: this.designNo,
          scrollY: window.api.pageParam.scrollY,
          keyLike: window.api.pageParam.keyLike
        });
      }
    },
    // 成品预计汇总
    onGetTableData() {
      let params = {};
      params.designNo = this.designNo;
      if (this.isColor) {
        params.color = this.color;
      } else {
        params.color = this.keyLike;
      }
      this.tableData = [];
      getProductExceptList(params, (res) => {
        this.tableData = res;
      });
    },
    onClickSearch() {
      this.pageNum = 1;
      this.onGetTableData();
    },
    onClickExceptDetail(data) {
      openWin("except-detail", {
        designNo: this.designNo,
        exceptDetails: data.exceptDetails,
        title: this.designNo + "(" + data.color + ")" + "(预计库存明细)",
        scrollY: this.$scroll.y,
        keyLike: this.keyLike,
      });
    }
  },
};
</script>

<style lang="scss">
.view-except {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  .van-search {
    width: 100%;
    position: relative;
    z-index: 999;
    
  }
  .van-cell__title {
      flex: 0 0 70%;
    }
  .public-scroll {
    flex: 1;
    overflow: hidden;
  }
}
</style>
